import com.t371.spring.dao.Mohe;
import com.t371.spring.dao.Printer;
import com.t371.spring.dao.Zhizhang;
import com.t371.spring.dao.impl.B5;
import com.t371.spring.dao.impl.HuiseMohe;
import com.t371.spring.entity.Baby;
import com.t371.spring.entity.Pet;
import com.t371.spring.service.PetService;
import com.t371.spring.service.impl.PetServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PetServiceTester {
    private PetService petService = null;

    @Before
    public void setUp(){
        //petService = new PetServiceImpl();
        ApplicationContext context =  new ClassPathXmlApplicationContext("applicationContext.xml");
        petService = (PetService) context.getBean("petService");
    }

    @Test
    public void testGetPet(){
        Pet pet = petService.getPet(1);
        System.out.println(pet.getName());
    }
    @Test
    public void TextConstructorDI(){
        ApplicationContext context=new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Baby baby=(Baby) context.getBean("redBoy");
        baby.introduce();
    }


    private Printer printer;
    @Test

    public void testPrinter(){
        String text="Hello, world!";
        printer.print(text);

        Mohe Mohe=new HuiseMohe();
        Zhizhang zhizhang=new B5();

        //更换墨盒和纸张
        printer.mohe(Mohe);
        printer.zhizhang(zhizhang);

        printer.print(text);
    }
}
